package com.link2room.quintesson.controller.manager;

import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.common.jpa.result.QueryResult;
import com.link2room.quintesson.dto.param.manager.TaobaoAccountsManagerParamDto;
import com.link2room.quintesson.facade.ITaobaoAccountsFacadeService;
import com.link2room.soundwave.dto.result.base.PmsAccountDto;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by VegetaKo on 2017/1/12.
 */
@RestController
@RequestMapping("/manager/TaobaoAccounts")
public class TaobaoAccountManagerController {

    @Resource
    private ITaobaoAccountsFacadeService taobaoAccountsFacadeService;

    @RequestMapping(value = "/Accounts",method = RequestMethod.GET)
    public BaseResultDto taobaoAccountList(
            @RequestParam(value = "lhotelCode" ,required = true) String lhotelCode,
            @RequestParam(value = "l2rNo" ,required = true) String l2rNo,
            @RequestParam(value = "crsNo" ,required = true) String crsNo
    ) throws Exception {
        TaobaoAccountsManagerParamDto taobaoAccountsManagerParamDto=new TaobaoAccountsManagerParamDto();
        taobaoAccountsManagerParamDto.setLhotelCode(lhotelCode);
        taobaoAccountsManagerParamDto.setL2rNo(l2rNo);
        taobaoAccountsManagerParamDto.setCrsNo(crsNo);
        QueryResult<PmsAccountDto> taobaoAccountsResult = taobaoAccountsFacadeService.listAccounts(taobaoAccountsManagerParamDto);
        BaseResultDto<PmsAccountDto> baseResultDto=new BaseResultDto<>();
        baseResultDto.setResultCode(0);
        baseResultDto.setQueryResult(taobaoAccountsResult);
        return baseResultDto;
    }

    @RequestMapping(value = "/Accounts/Count", method = RequestMethod.GET)
    public BaseResultDto taobaoAccountsCount(
            @RequestParam(value = "ids", required = false) List<Long> ids
    ) throws Exception {
        TaobaoAccountsManagerParamDto taobaoAccountsManagerParamDto=new TaobaoAccountsManagerParamDto();
        taobaoAccountsManagerParamDto.setIds(ids);
        BaseResultDto l2rRs = new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(taobaoAccountsFacadeService.getAccountResult(taobaoAccountsManagerParamDto));
        return l2rRs;
    }

    @RequestMapping(value = "/Accounts/Settle", method = RequestMethod.GET)
    public BaseResultDto taobaoAccountsSettle(
            @RequestParam(value = "l2rNo" ,required = true) String l2rNo
    ) throws Exception {
        TaobaoAccountsManagerParamDto taobaoAccountsManagerParamDto=new TaobaoAccountsManagerParamDto();
        taobaoAccountsManagerParamDto.setL2rNo(l2rNo);
        taobaoAccountsFacadeService.taobaoAccountSettle(taobaoAccountsManagerParamDto);
        BaseResultDto l2rRs = new BaseResultDto();
        l2rRs.setResultCode(0);
        return l2rRs;
    }
}
